#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

void CountSort(int* arr, int n)
{
	int i = 0; int max = arr[0]; int min = arr[0];
	for (i = 0; i < n; i++)
	{
		if (arr[i]>max)
			max = arr[i];
		if (arr[i] < min)
			min = arr[i];
	}
	int range = max - min + 1;
	int* count = (int*)malloc(range*sizeof(int));
	memset(count, 0, range*sizeof(int));
	for (i = 0; i < n; i++)
	{
		count[arr[i] - min]++;
	}
	int j = 0;
	for (i = 0; i < range; i++)
	{
		while (count[i]--)
		{
			arr[j] = i + min;
			j++;
		}	
	}
}

int main()
{
	int arr[] = { 6, 5, 4, 5, 6, 4, 2, 1, 9, 0 };
	int len = sizeof(arr) / sizeof(arr[0]);
	CountSort(arr,len);
	for (int i = 0; i < len; i++)
	{
		printf("%d ", arr[i]);
	}
	printf("\n");
	return 0;
}